
import { CHANGE_INPUT_VALUE, DEL_ITEM, ADD_ITEM, GET_LIST } from './constants'
const defaultState = {
  inputValue: 'test',
  list: [

  ]
}

export default (state = defaultState, action) => {
  let newState = JSON.parse(JSON.stringify(state))
  switch (action.type) {
    case CHANGE_INPUT_VALUE:
      newState.inputValue = action.value
      return newState
    case ADD_ITEM:
      newState.list = [...newState.list, { name: newState.inputValue }]
      return newState
    case DEL_ITEM:
      newState.list.splice(action.value, 1)
      return newState
    case GET_LIST:
      newState.list = action.value
      return newState
    default:
      return state
  }
}